package api

import (
	"2301a/yuekao/api/handler"
	"2301a/yuekao/api/middleware"
	"2301a/yuekao/consts"
	"github.com/gin-gonic/gin"
	jwt "github.com/golangblogs/gojwt"
)

func LoadRouter(r *gin.Engine) {
	r.Use(middleware.CorsMiddle())
	api := r.Group("api")
	{
		user := api.Group("user")
		{
			user.POST("/register", handler.UserRegister) //注册
			user.POST("/login", handler.UserLogin)       //登录
			user.Use(jwt.JWTAuth(consts.JWT_KEY))
			user.POST("/refresh", handler.RefreshToken) //刷新token
		}
		house := api.Group("house")
		{
			house.POST("/file", handler.HouseFile) //上传文件

			house.Use(jwt.JWTAuth(consts.JWT_KEY))
			house.POST("/add", handler.HouseAdd)           //房源发布接口
			house.GET("/list", handler.GetHouseList)       //房源列表接口
			house.GET("/details", handler.GetHouseDetails) //房源房源详情接口
			house.POST("/update", handler.UpdateHouse)     //房源修改接口
		}
		reservation := api.Group("reservation")
		{
			reservation.Use(jwt.JWTAuth(consts.JWT_KEY))
			reservation.POST("/showings/reservation", handler.ReservationShowings) //预约看房接口
			reservation.POST("/cancel/reservation", handler.ReservationCancel)     //取消看房接口
		}
		order := api.Group("order")
		{
			order.Use(jwt.JWTAuth(consts.JWT_KEY))
			order.POST("/add/buying", handler.AddOrder)  //创建购房意向订单接口+锁定房源状态
			order.POST("/voucher", handler.VoucherOrder) //首付款凭证接口+订单状态
			order.GET("/details", handler.DetailsOrder)  //管理员查看订单接口
			order.POST("/update", handler.UpdateOrder)   //管理员更新订单状态接口
		}
		chat := api.Group("chat")
		{
			chat.Use(jwt.JWTAuth(consts.JWT_KEY))
			chat.GET("/ws", handler.Chat)              //聊天
			chat.POST("/history", handler.ChatHistory) //聊天记录
		}
		admin := api.Group("admin")
		{
			admin.POST("/sensitive", handler.SensitiveAdmin)
		}
	}
}
